﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	XmlRuleExecutor.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;

namespace Smart.Common.Rules
{
	/// <summary>
	/// Xml rule executor
	/// </summary>
	public class XmlRuleExecutor : RuleExecutor
	{
		/// <summary>
		/// Xml rule executor
		/// </summary>
		public XmlRuleExecutor(RulesCtx ctx)
			: base(ctx)
		{
		}

		/// <summary>
		/// Apply rule action
		/// </summary>
		public virtual bool ApplyAction(XmlRuleActionMethod action)
		{
			throw new NotSupportedException("ApplyAction");
		}

		/// <summary>
		/// Apply rule action
		/// </summary>
		public override bool ApplyAction<TRuleActionType>(TRuleActionType action)
		{
			var ruleAction = action as XmlRuleAction;

			if (ruleAction != null)
			{
				if (ruleAction.Methods == null)
					return false;

				var res = false;

				for (int i = 0, iMax = ruleAction.Methods.Count; i < iMax; i++)
				{
					res |= ApplyAction(ruleAction.Methods[i]);
				}

				return res;
			}

			throw new NotSupportedException("ApplyAction");
		}
	}
}